<!--
 * @Description: 视频预览组件
 * @Author: liyujie
 * @Date: 2021/10/12
 * @Last Modified by: liyujie
 * @Last Modified time: 2021/10/12
-->
<template>
    <section class="wrapper">
        <el-dialog
            :visible.sync="dialogVisible"
            title=""
            width="960px"
            custom-class="zsdx-video-preview-dialog"
            @close="$emit('close')"
        >
            <video
                id="zsdx-video"
                class="video-preview"
                autoplay
                width="960px"
                height="540px"
                :controls="true"
                :src="previewUrl"
                v-if="previewUrl"
            >
                <source :src="previewUrl">
                <source :src="previewUrl">
                <object :data="previewUrl"/>
            </video>
        </el-dialog>
    </section>
</template>

<script>
import Vue from "vue";

const Dialog = {
    name: "VideoPreview",
    props: {
        previewUrl: {
            type: String,
            default: ''
        },
    },
    data() {
        return {
            dialogVisible: false
        };
    },
    mounted() {},
    methods: {

        /**
         * 显示弹窗
         */
        show() {
            this.dialogVisible = true;
        },

        /**
         * 显示弹窗
         */
        close() {
            this.dialogVisible = false;
        },
    }
};

export default Dialog;

const videoPreviewDialog = function (config) {
    return new Promise((resolve) => {
        const DialogConstructor = Vue.extend(Dialog);
        const instance = new DialogConstructor({
            propsData: config,
        }).$mount();

        instance.$on("close", function () {
            setTimeout(() => {
                document.body.removeChild(instance.$el);
                instance.$destroy();
            }, 300);
            resolve(false);
        });
        instance.$on("confirm", function (data) {
            instance.close();
            resolve(data);
        });
        document.body.appendChild(instance.$el);
        instance.dialogVisible = true;
    });
};

export { videoPreviewDialog };
</script>

<style scoped lang="less">
</style>
<style lang="less">
.zsdx-video-preview-dialog {
    .el-dialog__headerbtn{
        z-index: 9999;
        top: 10px;
        .el-dialog__close {
            color: #fff;
            cursor: pointer;
        }
    }
    .el-dialog__header{
        height: 0;
        padding: 0;
    }
    .el-form--label-top .el-form-item__label {
        padding: 0;
    }
    .el-dialog__body {
        padding: 0;
        background: #000;;
    }
    .dialog-edit-footer {
        text-align: center;
        margin-top: 0;
    }
    .el-form-item {
        margin-bottom: 0;
    }

    &:hover {
        .controls {
            display: block;
        }
    }
    .controls {
        width: 960px;
        height: 70px;
        position: absolute;
        left: 0;
        bottom: 0;
        z-index: 9999;
        box-sizing: border-box;
        color: #fff;
        display: flex;
        padding: 0 24px;
        flex-direction: column;
        display: none;
        .controls_header {
            height: 36px;
            width: 100%;
            display: flex;
            align-items: center;
            color: #fff;
            justify-content: space-between;
            padding-right: 70px;
            ._vode_left {
                display: flex;
                align-items: center;
                .conterols_wrap {
                    width: 36px;
                    height: 36px;
                    border-radius: 50%;
                    display: flex;
                    justify-content: center;
                    align-items: center;
                    cursor: pointer;
                    margin-right: 8px;
                    &:hover {
                        background: rgba(0,0,0,.4);
                    }
                    .iconfont {
                        color: #fff;
                        font-size: 16px;
                    }
                }
                ._video_time {
                    color: #fff;
                    font-size: 12px;
                    font-weight: 500;
                }
            }
            ._video_right {
                cursor: pointer;
            }
        }
        ._video_load {
            height: 18px;
            width: 912px;
            // border: 1px red solid;
            display: flex;
            align-items: center;
            position: relative;
            cursor: pointer;
            ._video_box {
                width: 912px;
                height: 6px;
                background: rgba(0, 0, 0, 0.1);
                border-radius: 3px;
                position: relative;
                ._video_next {
                    height: 6px;
                    border-radius: 3px;
                    background: #fff;
                    // transition: all .2s linear;
                }
            }
        }
    }
    ._content {
        width: 960px;
        height: 450px;
        position: absolute;
        left: 0;
        top: 0;
        ._content_text {
            color: #f3f3f3;
            font-size: 14px;
            position: relative;
            top: 100px;
            transform: rotate(-25deg);
            opacity: .5;
        }
        ._content_text2 {
            color: #f3f3f3;
            font-size: 14px;
            position: relative;
            top: 186px;
            left: 242px;
            -ms-transform: rotate(-25deg);
            transform: rotate(-25deg);
            opacity: .5;
        }
    }
}
</style>
